#include "widget.h"
#include "ui_widget.h"

#include<QDebug>
#include<QMouseEvent>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //鼠标点击事件

    //通过事件分发器，拦截 鼠标按下事件

}

Widget::~Widget()
{
    delete ui;
}

void Widget::mousePressEvent(QMouseEvent *event)
{
    if(event->button()==Qt::LeftButton)
    {
       qDebug()<<"按下左键了";
    }
    if(event->button()==Qt::RightButton)
    {
        qDebug()<<"按下右键了";
    }
}
bool Widget::event(QEvent *event)
{
    if(event->type()==QEvent::MouseButtonPress)
    {
        qDebug()<<"Event中左键被按下了";
        return true;
    }
    return QWidget::event(event);
}
